package org.example.struct.array;

/**
 * @author liyishan
 * @date 2023/12/7 09:32
 * @apiNote
 */

public class Test02490IsCircularSentence {

    public boolean isCircularSentence(String sentence) {
        String[] word = sentence.split(" ");
        int n = word.length;
        char firstOne = word[0].charAt(0);
        char lastOne = word[n - 1].charAt(word[n - 1].length() - 1);
        if(firstOne != lastOne){
            return false;
        }
        for(int i = 0; i < n-1; i++){
            char last = word[i].charAt(word[i].length() - 1);
            char first = word[(i + 1) % n].charAt(0);
            if(last != first){
                return  false;
            }
        }
        return true;
    }


    public static boolean test(String sentence) {
        if (sentence.charAt(sentence.length() - 1) != sentence.charAt(0)) {
            return false;
        }
        for (int i = 0; i < sentence.length(); i++) {
            if (sentence.charAt(i) == ' ' && sentence.charAt(i + 1) != sentence.charAt(i - 1)) {
                return false;
            }
        }
        return true;
    }
}
